package com.ruoyi.training.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.training.dto.certificate.CertificateIssueDto;
import com.ruoyi.training.dto.certificate.GenerateElectronicSelectDto;
import com.ruoyi.training.service.ICertificateIssueService;
import com.ruoyi.training.vo.certificate.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.training.domain.CertificateIssue;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 经营性证书管理Controller
 *
 * @author hcc
 * @date 2025-11-06
 */
@RestController
@RequestMapping("/certificateIssue")
public class CertificateIssueController extends BaseController
{
    @Autowired
    private ICertificateIssueService certificateIssueService;

    /**
     * 查询证书发放管理列表
     */
    @RequiresPermissions("training:certificateIssue:list")
    @GetMapping("/list")
    public TableDataInfo list(CertificateIssue certificateIssue)
    {
        startPage();
        List<CertificateIssue> list = certificateIssueService.selectCertificateIssueList(certificateIssue);
        return getDataTable(list);
    }

    /**
     * 导出证书发放管理列表
     */
    @RequiresPermissions("training:certificateIssue:export")
    @Log(title = "证书发放管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CertificateIssue certificateIssue)
    {
        List<CertificateIssue> list = certificateIssueService.selectCertificateIssueList(certificateIssue);
        ExcelUtil<CertificateIssue> util = new ExcelUtil<CertificateIssue>(CertificateIssue.class);
        util.exportExcel(response, list, "证书发放管理数据");
    }

    /**
     * 获取证书发放管理详细信息
     */
    @RequiresPermissions("training:certificateIssue:query")
    @GetMapping(value = "/{certificateIssueId}")
    public AjaxResult getInfo(@PathVariable("certificateIssueId") String certificateIssueId)
    {
        return success(certificateIssueService.selectCertificateIssueByCertificateIssueId(certificateIssueId));
    }

    /**
     * 新增证书发放管理
     */
    @RequiresPermissions("training:certificateIssue:add")
    @Log(title = "证书发放管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CertificateIssue certificateIssue)
    {
        return toAjax(certificateIssueService.insertCertificateIssue(certificateIssue));
    }

    /**
     * 修改证书发放管理
     */
    @RequiresPermissions("training:certificateIssue:edit")
    @Log(title = "证书发放管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CertificateIssue certificateIssue)
    {
        return toAjax(certificateIssueService.updateCertificateIssue(certificateIssue));
    }

    /**
     * 删除证书发放管理
     */
    @RequiresPermissions("training:certificateIssue:remove")
    @Log(title = "证书发放管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{certificateIssueIds}")
    public AjaxResult remove(@PathVariable String[] certificateIssueIds)
    {
        return toAjax(certificateIssueService.deleteCertificateIssueByCertificateIssueIds(certificateIssueIds));
    }

    /**
     * 查询证书发放管理列表
     */
//    @RequiresPermissions("training:certificateIssue:list")
    @GetMapping("/getCertificateIssueList")
    public TableDataInfo getCertificateIssueList(CertificateIssueVo certificateIssueVo)
    {
        startPage();
        List<CertificateIssueDto> list = certificateIssueService.getCertificateIssueList(certificateIssueVo);
        return getDataTable(list);
    }

    /**
     * 新增证书发放管理
     */
    @RequiresPermissions("training:certificateIssue:add")
    @Log(title = "证书发放管理", businessType = BusinessType.INSERT)
    @PostMapping("/addCertificateIssue")
    public AjaxResult addCertificateIssue(@RequestBody CertificateIssue certificateIssue)
    {
        return toAjax(certificateIssueService.addCertificateIssue(certificateIssue));
    }


    /**
     * 生成电子证书数据查询
     */
    @RequiresPermissions("training:certificateIssue:query")
    @GetMapping("/getGenerateElectronicSelect")
    public AjaxResult getGenerateElectronicSelect(GenerateElectronicSelectVo generateElectronicSelectVo)
    {
        startPage();
        GenerateElectronicSelectDto generateElectronicSelectDto = certificateIssueService.getGenerateElectronicSelect(generateElectronicSelectVo);
        return success(generateElectronicSelectDto);
    }

    /**
     * 生成电子证书
     */
    @RequiresPermissions("training:certificateIssue:edit")
    @Log(title = "证书发放管理", businessType = BusinessType.UPDATE)
    @PutMapping("/generateElectronic")
    public AjaxResult generateElectronic(@RequestBody GenerateElectronicVo generateElectronicVo)
    {
        return toAjax(certificateIssueService.generateElectronic(generateElectronicVo));
    }

    /**
     * 撤销电子证书
     */
    @RequiresPermissions("training:certificateIssue:edit")
    @Log(title = "证书发放管理", businessType = BusinessType.UPDATE)
    @PutMapping("/cancelElectronic")
    public AjaxResult cancelElectronic(@RequestBody CancelElectronicVo cancelElectronicVo)
    {
        return toAjax(certificateIssueService.cancelElectronic(cancelElectronicVo));
    }

    /**
     * 查看电子证书
     */
    @RequiresPermissions("training:certificateIssue:query")
    @GetMapping(value = "/getElectronicInfo/{certificateIssueIds}")
    public AjaxResult getElectronicInfo(@PathVariable String[] certificateIssueIds)
    {
        return success(certificateIssueService.getElectronicInfo(certificateIssueIds));
    }

    /**
     * 快递发放证书
     */
    @RequiresPermissions("training:certificateIssue:edit")
    @Log(title = "证书发放管理", businessType = BusinessType.UPDATE)
    @PutMapping("/expressPaperCertificate")
    public AjaxResult expressPaperCertificate(@RequestBody ExpressElectronicVo expressElectronicVo)
    {
        return toAjax(certificateIssueService.expressPaperCertificate(expressElectronicVo));
    }

    /**
     * 现场领取证书
     */
    @RequiresPermissions("training:certificateIssue:edit")
    @Log(title = "证书发放管理", businessType = BusinessType.UPDATE)
    @PutMapping("/scenePaperCertificate/{certificateIssueIds}")
    public AjaxResult scenePaperCertificate(@PathVariable("certificateIssueIds") String[] certificateIssueIds)
    {
        return toAjax(certificateIssueService.scenePaperCertificate(certificateIssueIds));
    }
}
